#ifndef _MAP_H_ 
#define _MAP_H_
#include <string>

class Map
{
public:
  Map(void);
  ~Map(void);
                   
  // Used as an intermediate step to allow a double bracket operation
  // such as [i][j] on the Map.  For example, myMap[row][col] = 0;
  class bracket
  {
  public:
    bracket(int* d, int i) : data(d), offset(i) {}
    int& operator [] (int col) {return data[offset+col];}
  private:
    int offset;
    int* data;
  };

  int width(void) const {return w;}
  int height(void) const {return h;}
  int size(void) const {return _size;}
  const int* data(void) const {return dataPtr;}
  
  void clear(void);
  void setData(int width, int height, const int* d);
  void resize(int width, int height);
  bool isValid(int row, int col) const;
  bool isBarrier(int row, int col) const;
  int index(int row, int col) const;  
  int getValue(int index) const;
  int getValue(int row, int col) const;
  void setValue(int row, int col, int value);
  void getRowCol(int index, int& row, int& col) const;
  bracket operator [] (int row);
  
  bool readFile(const std::string& path);
  void print(std::ostream& os);
  
private:
  bool getStrAfterIfMatch(const std::string& str,
                          const std::string& key,
                          std::string& value);  
private:
  int w;  // width
  int h;  // height
  int _size;  // size
  int* dataPtr;
};

#endif // _MAP_H_ 
